package biz;

import dao.*;
import utils.DBHelper;

import java.util.List;
import java.util.Map;

public class userBiz {

    UserLoginDao dao =new UserLoginDao();
    UserLogonDao dao1=new UserLogonDao();
    QueryUserdao dao2=new QueryUserdao();
    AddressDao dao3=new AddressDao();
    QuerylistDao dao4=new QuerylistDao();
    public Map<String,Object> login(String username, String pwd){
        return dao.userLogin(username,pwd);
    }

    public void insert(String username,String telphone,String password,String email) throws BizException {
        if (username==null||username.trim().isEmpty()){
            throw new BizException("用户名不能为空");
        }
        if (telphone==null||telphone.trim().isEmpty()){
            throw new BizException("电话号不能为空");
        }
        if (password==null||password.trim().isEmpty()){
            throw new BizException("密码不能为空");
        }
        if (email==null||email.trim().isEmpty()){
            throw new BizException("邮件不能为空");
        }
        dao1.insert(username,telphone,password,email);
    }

    public void update(Integer uid,String password) throws BizException {
        if (uid==null&&password.trim().isEmpty()){
            throw new BizException("输入有误");
        }else {
            dao2.update_pwd(uid,password);
        }

    }

    public List<Map<String,Object>> queryadd(Integer uid) throws BizException {
        if (uid==null){
            throw new BizException("输入有误");
        }else {
            return dao2.queryadd(uid);
        }
    }

    public void add_address( String name,String telphone,Integer uid,String site) throws BizException {

        if (name==null||name.trim().isEmpty()){
            throw new BizException("收货人不能为空");
        }
        if (telphone==null||telphone.trim().isEmpty()){
            throw new BizException("收货人电话不能为空");
        }
        if (site==null||site.trim().isEmpty()){
            throw new BizException("详细地址不能为空");
        }

        dao3.add_address(name,telphone,uid,site);
    }


    public int exists(String username, String email){
        return dao.exists(username, email);
    }

    public void modify(String username, String password, String email){
        dao.modify(username, password, email);
    }

    public void setdafault(Integer address, Integer id) throws BizException {

        if (address==null){
            throw new BizException("地址不能为空");
        }
        dao4.setdefault(address,id);
    }

    public Map<String, Object> userAddress(String uid){
        return dao.userAddress(uid);
    }
}
